﻿#include "cglasseffect.h"

#include <windows.h>
#include <QDebug>

CglasseFfect::CglasseFfect(QWidget *parent)
    : QMainWindow{parent}
{
    //setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
    //setWindowFlags( Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);//背景半透明属性设置   //窗口透明


    HWND hWnd = HWND(this->winId());
    HMODULE hUser = GetModuleHandle("user32.dll");
    if (hUser)
    {


        pfnSetWindowCompositionAttribute setWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(hUser, "SetWindowCompositionAttribute");
        if (setWindowCompositionAttribute)
        {
            ACCENT_POLICY accent = { ACCENT_ENABLE_BLURBEHIND, 0, 0, 0 };
            WINDOWCOMPOSITIONATTRIBDATA data;
            data.Attrib = WCA_ACCENT_POLICY;
            data.pvData = &accent;
            data.cbData = sizeof(accent);
            setWindowCompositionAttribute(hWnd, &data);
        }
    }


    bgColor = new QColor(0, 0, 0,1);
}
CglasseFfect::~CglasseFfect()
{

}


void CglasseFfect::setGlassBackgroundR(int R)
{
    bgColor->setRed(R);


}
void CglasseFfect::setGlassBackgroundG(int G)
{
    bgColor->setGreen(G);

}
void CglasseFfect::setGlassBackgroundB(int B)
{
    bgColor->setBlue(B);

}
void CglasseFfect::setGlassBackgroundA(int A)
{
    bgColor->setAlpha(A);

}


void CglasseFfect::paintEvent(QPaintEvent * ev)
{

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::NoPen);
    painter.setBrush(*bgColor);
    //painter.drawRoundedRect(rect(), 20, 20);   //界面圆角
    painter.drawRect(0, 0, width(), height());



}
